
#ifndef __UNIT_H__
#define __UNIT_H__

#include <string>
#include <vector>
using namespace std;

class Unit;
class UnitType;
class Formatter;
typedef std::vector<const Unit *>  OrderedUnits;

enum eUnitType
{
	E_LENGTH_TYPE,
	E_VOLUME_TYPE,
	E_INVALID_TYPE
};

class Unit
{
public:
	static const Unit& getInvalidUnit();
	virtual const Unit& getBaseUnit() const {};
	bool hasSameUnitType(const Unit & unit) const ;
	int convertToNormalizedAmount(int length) const;

	virtual void printOrderedUnitsList(const Formatter& formatter) const {};
	virtual void printBaseUnitList(const Formatter& formatter) const;
	
	void getFloorUnitStream(std::ostream& out, int amountInBaseUnit, bool& firstUnitFound) const;
	int getRestAmountInBaseUnit(int amountInBaseUnit) const;

	bool operator > (const Unit & unit) const;
	friend std::ostream& operator<<(std::ostream& out, const Unit& unit);

protected:
	Unit(int factor, string name, const eUnitType unitType);
	virtual void appendAndSortUnit(OrderedUnits & orderedunits, const Unit & unit) const;

	int factor_m;
	string name_m;
	const eUnitType unitType_m;

};

#define INVALID_UNIT Unit::getInvalidUnit()



#endif
